package com.yonyou.pmclouds.billtype.util;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.outter.nc.NcDeptCustomerQuery;
import com.yonyou.pmclouds.plan.plandriven.entity.NcDepartmentVO;
import com.yonyou.pmclouds.plan.plandriven.entity.NcDeptQueryParamVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @Description: 根据部门主键获取部门名称
 * @Author: zhangzhonghao
 * @Date: 2020-03-06
 *
 */
@Component
public class DepartmentInfoQueryUtils {

    @Autowired
    private NcDeptCustomerQuery ncDeptCustomerQuery;

    public Map<String, String> queryNameByPks(String[] pkDepartments) throws BusinessException{
        Map<String, String> result = new HashMap<>();

        if(pkDepartments == null || pkDepartments.length <= 0){
            return result;
        }

        List<NcDepartmentVO> ncDepartmentVOs = ncDeptCustomerQuery
                .queryDepartmentFromNc(new NcDeptQueryParamVO(null, null, Arrays.asList(pkDepartments)));

        if (CollectionUtils.isEmpty(ncDepartmentVOs))
            return result;

        for (NcDepartmentVO vo : ncDepartmentVOs) {
            result.put(vo.getPkDept(), vo.getName());
        }

        return result;
    }

    public List<NcDepartmentVO> queryDepartment(NcDeptQueryParamVO deptQueryParamVO){
        return ncDeptCustomerQuery.queryDepartmentFromNc(deptQueryParamVO);
    }
}
